package com.socool.sinofaith.adapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.socool.sinofaith.R;
import com.socool.sinofaith.model.InvestigatesReportResponse.ReportData.Data;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Report2Adapter extends BaseAdapter {

	private Context context;
	private LayoutInflater inflater;
	private List<Data> list = new ArrayList<Data>();

	public Report2Adapter(Context context) {
		this.context = context;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Data getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Report2ViewHolder mViewHolder = null;
		if (convertView == null) {
			mViewHolder = new Report2ViewHolder();
			convertView = inflater.inflate(R.layout.adapter_report2, parent, false);
			mViewHolder.bindView(convertView);
			convertView.setTag(mViewHolder);
		} else {
			mViewHolder = (Report2ViewHolder) convertView.getTag();
		}
		initViewHolder(mViewHolder, position);
		return convertView;
	}

	private void initViewHolder(Report2ViewHolder mViewHolder, int position) {
		final Data data = getItem(position);
		mViewHolder.tvName.setText(data.getName());
		mViewHolder.tvData.setText(data.getData());
	}

	public void replace(Collection<Data> collection) {
		list.clear();
		list.addAll(collection);
		notifyDataSetChanged();
	}

}

class Report2ViewHolder {
	TextView tvName;
	TextView tvData;

	public void bindView(View convertView) {
		tvName = (TextView) convertView.findViewById(R.id.tvName);
		tvData = (TextView) convertView.findViewById(R.id.tvData);
	}

}
